/**
 * \class CTorus
 * \brief This is a 2-d torus like doughnut
 * \breif The structure is like the below:
 * \brief (0,0) (0,1) ~ (0,j)
 * \brief (1,0) (1,1) ~ (1,j)
 * \brief ~
 * \brief (i,0) (i,1) ~ (i,j).
 * 
 * \version 0.3.2
 *
 * \author Woo-Hyun Kim (woorung@nhncorp.com, woorung@gmail.com)
 * \author http://blog.naver.com/wisereign .
 *
 * \date 2008/6/18
 */
//----------------------------------------------------------------------
#include "CTorus.h"
//----------------------------------------------------------------------
CTorus::CTorus(long rows, long columns)
{
	this->rows = rows;
	this->columns = columns;
}
//----------------------------------------------------------------------
CTorus::~CTorus()
{
}
//----------------------------------------------------------------------
pair<long,long> &CTorus::up(pair<long,long> &pos)
{
	long i = pos.first;

	// up
	pos.first = (rows+i-1)%rows;

	return pos;
}
//----------------------------------------------------------------------
pair<long,long> &CTorus::down(pair<long,long> &pos)
{
	long i = pos.first;

	// down
	pos.first = (i+1)%rows;

	return pos;
}
//----------------------------------------------------------------------
pair<long,long> &CTorus::right(pair<long,long> &pos)
{
	long j = pos.second;

	// right
	pos.second = (j+1)%columns;

	return pos;
}
//----------------------------------------------------------------------
pair<long,long> &CTorus::left(pair<long,long> &pos)
{
	long j = pos.second;

	// left
	pos.second = (columns+j-1)%columns;
	
	return pos;
}
//----------------------------------------------------------------------
